#ifndef SEQSTACK_H
#define SEQSTACK_H

#include<iostream>
#include<assert.h>
using namespace std;
#include"Stack.h"

const int stackIncrement = 50;
template<class T>
class SeqStack: public Stack<T> {
	public:
		SeqStack(int sz = 50);
		~SeqStack(){ delete []elements; }
	public:
		void Push(const T& x);
		bool Pop(T& x);
		bool getTop(T& x);
		bool IsEmpty()const ;
		bool IsFull()const;
		int getSize()const ;
		void MakeEmpty();
		friend ostream& operator << (ostream& os ,SeqStack<T>& s ){
			return os;
		}

	private:
		void overflowProcess();
	private:
		T * elements;
		int top;
		int maxSize;

};


template< class T>
SeqStack<T>::SeqStack(int sz):top(-1),maxSize(sz){
	elements = new T[maxSize];
	assert(elements!=NULL);
}


template<class T>
void SeqStack<T>::Push(const T& x){
	if(IsFull())
		overflowProcess();
	elements[++top] = x;
	return;
}

template<class T>
bool SeqStack<T>::Pop(T& x){
	if(IsEmpty())
		return false;
	else
		x = elements[top--];
	return true;
}

template<class T>
bool SeqStack<T>::getTop(T& x){
	if(IsEmpty())
		return false;
	x = elements[top];
	return true;
}

template<class T>
bool SeqStack<T>::IsEmpty()const{
	if(top ==-1)
		return true;
	else
		return false;
}

template<class T>
bool SeqStack<T> ::IsFull()const{
	if(top == maxSize -1)
		return true;
	else
		return false;
}
template<class T>
int SeqStack<T>::getSize()const {
	return top+1;
}

template<class T>
void SeqStack<T>::MakeEmpty(){
	top=-1;
}


template<class T>
void SeqStack<T>::overflowProcess(){
	T * newArray = new T[maxSize + stackIncrement];
	assert(newArray!=NULL);
	for(int i=0;i<=top;i++)
		newArray[i] = elements[i];
	maxSize += stackIncrement;
	delete elements;
}
#endif
